'use strict';

// var koa = require('./koa/koa');
// var koaRouter = require('./koa/koa-router');

const Koa = require('koa');
const app = new Koa();

const bodyParser = require('koa-bodyparser');

var templating = require('./koa/templating');

var controller = require('./controller');

app.use(async (ctx, next) => {
    console.log(`Process ${ctx.request.method} ${ctx.request.url}...`);
var
    start = new Date().getTime(),
    execTime;
await next();
execTime = new Date().getTime() - start;
ctx.response.set('X-Response-Time', `${execTime}ms`);
});

// 处理静态资源
// let staticFiles = require('./koa/static-files');
// app.use(staticFiles('/static/', __dirname + '/static'));


app.use(bodyParser());

app.use(templating('./view', {
    noCache: true,
    watch: true
}));


app.use(controller());

app.listen(3000);
console.log('app started at port 3000...');